package basic.courseLearn01;


import basic.courseLearn01.utils.FunctionSort;
import basic.courseLearn01.utils.SortUtils;
import org.junit.Test;

//插入排序(从小到大)
public class InsertSorting implements FunctionSort {

    //开始将第1个为有序序列,然后将第2个数插入到有序序列中(从后往前交换)...
    public int[] insertSort(int [] result){
        for (int i = 0; i < result.length-1; i++) {     //共进行n-1次插入,0-i为有序
            for (int j = i+1; j > 0; j--) {
                if (result[j]<result[j-1]){
                    SortUtils.swap(result,j,j-1);
                }
            }
        }
        return result;
    }

    @Override
    public int[] sort(int[] result) {
        return insertSort(result);
    }

    @Test
    public void test(){
        SortUtils.executeCheckAlgorithm(1_0000,1000,1000,this);
    }


}
